#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011 BidiX (http://bidix.info)
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
'''
Created on 2011-11-08

@author: BidiX

	Wrapper for django template in GAE
'''

import template

class Page():
	
	def __init__(self, response, context={}):
		self.response = response
		self.context = context
		self.template_name = self.__class__.template_name
		
		self.generate()

	def generate(self):
		self.write(template.render(self.template_name, self.context), 'text/html')
		
	def write(self, page, content_type = "text/html"):
		self.response.headers['Content-Type'] = content_type
		self.response.headers['Cache-Control'] = 'no-cache'
		self.response.out.write(page)

class ErrorPage(Page):
	pass
class NotFoundPage(ErrorPage):
	template_name = '404'

class ArticleNotFoundPage(ErrorPage):
	template_name = 'article_not_found'
	
class ForbiddenPage(ErrorPage):
	template_name = '401'

class ArticlePage(Page):
	template_name = 'article_display'
	
class ArticleFormPage(Page):
	template_name = 'article_form'
	template_context = {
					}

class ArticleListPage(Page):
	template_name = 'article_list'
	template_context = {
					}


class ArticleMovePage(Page):
	template_name = 'article_move'
	template_context = {
					}

class ImportPage(Page):
	template_name = 'import'
	template_context = {
					}
	
class TagListPage(Page):
	template_name = 'tag_list'
	template_context = {
					}
	